﻿Imports System.Data.OleDb

Public Class AddCar
    Inherits System.Web.UI.Page


    Protected Sub btnAddCar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAddParrot.Click
        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".jpg"
        If txtImage.HasFile Then
            Dim FileOnDisk = Request.MapPath("Images") & "/" & newFileName
            txtImage.SaveAs(FileOnDisk)
        End If
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim sql = "INSERT INTO Parrot (Species,Breed,ParrotSize,LifeSpan,NoiseLevel,TalkingAbility,SuitableFor,Affectionate,Playful,Picture) VALUES (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9,@f10)"
        Dim cmd = New OleDbCommand(sql, conn)

        cmd.Parameters.AddWithValue("@f1", tb_Specie.Text)
        cmd.Parameters.AddWithValue("@f2", tb_Breed.Text)
        cmd.Parameters.AddWithValue("@f3", ddl_Size.Text)
        cmd.Parameters.AddWithValue("@f4", tb_LifeSpan.Text)
        cmd.Parameters.AddWithValue("@f5", ddl_NoiseLevel.SelectedValue)
        cmd.Parameters.AddWithValue("@f6", ddl_TalkingAbility.SelectedValue)
        cmd.Parameters.AddWithValue("@f7", ddl_SuitableFor.SelectedValue)
        cmd.Parameters.AddWithValue("@f8", cb_Affectionate.Checked)
        cmd.Parameters.AddWithValue("@f9", cb_PlayFul.Checked)
        cmd.Parameters.AddWithValue("@f10", "Images/" & newFileName)

        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        Response.Redirect("list.aspx")
    End Sub
    
End Class